package mulMan.domain;

import java.util.HashSet;
import java.util.Observable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "PLAYLIST")
public class Playlist  extends Observable{
	
	private int idPlaylist;
	private String name;
	private Set<AudioFile> audioFiles = new HashSet<AudioFile>(0);
	
	public Playlist() {
		
	}
	
	
	//Getters and Setters
	@Id
	@GeneratedValue
	@Column(name = "ID_PLAYLIST")
	public int getIdPlaylist() {
		return idPlaylist;
	}
	public void setIdPlaylist(int idPlaylist) {
		this.idPlaylist = idPlaylist;
		setChanged();
		notifyObservers("id");
	}
	@Column(name = "NAME")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
		setChanged();
		notifyObservers("name");
	}
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "playlist_audio_file", joinColumns = { 
			@JoinColumn(name = "ID_PLAYLIST", nullable = false, updatable = false) }, 
			inverseJoinColumns = { @JoinColumn(name = "ID_AUDIO_FILE", 
					nullable = false, updatable = false) })
	public Set<AudioFile> getAudioFiles() {
		return audioFiles;
	}
	public void setAudioFiles(Set<AudioFile> audioFiles) {
		this.audioFiles = audioFiles;
		setChanged();
		notifyObservers("list");
		System.out.println("5");
	}
	public String toString() {
		return name;
	}
	
	

}
